<?php

namespace library;

/**
 * Description of Mail
 *
 * @author Damian
 */
class Mail extends \PHPMailer {

    public function __construct() {
        parent::__construct(true);
        $this->SetLanguage("pl", "/");
        $this->CharSet = "UTF-8";
        try{
        $this->IsSMTP();
        $this->SMTPAuth = false;
// $this->IsSMTP();
//        $this->SMTPAuth = true;
//
//        $this->host = 'http://mail.platforma.damian-jozwiak.kylos.pl';
//        $this->Username = 'administrator@platforma.damian-jozwiak.kylos.pl';  
//        $this->Port=25;
//        $this->Password = 'Ad@miN12';                           // SMTP password
//        $this->SMTPSecure = '';
                   // SMTP password
        $this->From = 'administrator@platforma.damian-jozwiak.kylos.pl';
        //$this->AddAddress('damianjozw@wp.pl', 'Damian Jóźwiak');
        }
 catch (Exception $e){
            var_dump($e);
 }
    }

    /**
     * 
     * @param type $subject
     * @param type $message
     * @param type $from
     * @param type $attachment
     * @throws exceptions\MailException
     */
    public function sendEmail($subject, $message, $from, $attachment = false) {
        $words = explode(" ", $message);
        if (sizeof($words) < 5) {
            throw new exceptions\MailException("Wiadomość jest za krótka");
        }
        $this->FromName = $from;
        $message = \wordwrap($message, 70, "\r\n");
        $this->Subject = $subject;
        if ($attachment) {
            $this->AddAttachment($attachment);
        }
        $this->IsHTML();
        $this->Body = $message;
        if (!parent::Send()) {
            throw new exceptions\MailException("Wiadomość nie została wysłana " . $this->ErrorInfo);
        }
    }

}
